Namespace MPTools
    Namespace Strings

#Region " TagExtractor "
        ''' <summary>
        ''' Tag Extractor
        ''' </summary>
        ''' <remarks></remarks>
        Public Class TagExtractor
            Public Function ExtractTags(ByVal DataStr As String, ByVal StartTag As String, ByVal EndTag As String, Optional ByVal ReturnNameOnly As Boolean = False) As String()
                Dim SPos As Integer = 0
                Dim EPos As Integer = -1
                Dim TArray() As String = {}
                Dim TCount As Integer = 0
                ' Dim TArray As New ObjectModel.Collection(Of String)

                Do While SPos > -1
                    'loop through tag extracting tags
                    SPos = DataStr.IndexOf(StartTag, SPos)
                    If SPos > -1 Then
                        EPos = DataStr.IndexOf(EndTag, SPos)
                        If EPos > -1 Then
                            'extract the data with tags
                            If ReturnNameOnly = True Then
                                TCount = TCount + 1
                                Array.Resize(TArray, TCount)
                                TArray(TCount - 1) = StringTags(DataStr.Substring(SPos, (EPos + (EndTag.Length)) - SPos), StartTag, EndTag)
                                ' TArray.Add(StringTags(DataStr.Substring(SPos, (EPos + (EndTag.Length)) - SPos), StartTag, EndTag))
                            Else
                                TArray(TCount) = DataStr.Substring(SPos, (EPos + (EndTag.Length)) - SPos)
                                'TArray.Add(DataStr.Substring(SPos, (EPos + (EndTag.Length)) - SPos))
                            End If
                            SPos = (EPos + (EndTag.Length))
                        End If
                    End If
                Loop
                Return TArray
            End Function
            Public Function StringTags(ByVal DataStr As String, ByVal StartTag As String, ByVal EndTag As String) As String
                Dim Tstr As String = DataStr
                Tstr = Tstr.Replace(StartTag, "")
                Tstr = Tstr.Replace(EndTag, "")
                Return Tstr
            End Function
        End Class
#End Region

        Public Class StringData
            'strips nukbers from end of a string
            Public Shared Function RemoveNumbersFromEnd(ByVal Value As String) As String
                Dim TValue As String = Value
                For i As Integer = Value.Length - 1 To 0 Step -1
                    If IsNumeric(Value.Substring(i, 1)) = False Then
                        Return Value.Substring(0, i + 1)
                    End If
                Next
                Return Value
            End Function
            'strips numbers fro the start of a string
            Public Shared Function RemoveNumbersFromStart(ByVal Value As String) As String
                Dim TValue As String = Value
                For i As Integer = 0 To Value.Length - 1
                    If IsNumeric(Value.Substring(i, 1)) = False Then
                        Return Value.Substring(i, Value.Length - i)
                    End If
                Next
                Return Value
            End Function
            'strips numbers from the string
            Public Shared Function RemoveNumbers(ByVal Value As String) As String
                Dim TValue As String = ""
                For i As Integer = 0 To Value.Length - 1
                    If IsNumeric(Value.Substring(i, 1)) = False Then
                        TValue = TValue & Value.Substring(i, 1)
                    End If
                Next
                Return Value
            End Function
            Public Shared Function SubstringStartEnd(ByVal Value As String, ByVal StartPos As String, ByVal EndPos As String) As String
                If StartPos < EndPos Then
                    Dim TValue As String = ""
                    TValue = Value.Substring(StartPos, Value.Length - EndPos)
                    Return TValue
                End If
                Return Value
            End Function
        End Class


       
    End Namespace
End Namespace